<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.google.memoryofaplace.BLAdmins" %>
<%
UserService userService = UserServiceFactory.getUserService();
%>

<html>
    <head>
        <title>MemoryOfAPlace - Admin</title>
        <link href="/css/admin.css" rel="stylesheet" type="text/css" />
        <META http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <link href="/media/dataTables/page.css" rel="stylesheet" type="text/css" />
        <link href="/media/dataTables/table.css" rel="stylesheet" type="text/css" />
        <link href="/media/dataTables/table_jui.css" rel="stylesheet" type="text/css" />
        <link href="/css/smoothness/jquery-ui-1.8.13.custom.css" rel="stylesheet" type="text/css"  />
        <link href="/css/jquery.jgrowl.css" rel="stylesheet" type="text/css"  /> 

        <style type="text/css">
            label {
                display: block;
                text-align: right;
                float: left;
                width: 150px;
                padding-right: 10px;
            }

            #loadingScreen {
                background: url(/media/images/loading.gif) no-repeat 5px 8px;
                padding-left: 25px;
            }

            /* hide the close x on the loading screen */
            .loadingScreenWindow .ui-dialog-titlebar-close {
                display: none;
            }


            label.error {color: red; vertical-align: top;margin-left: 160px; width: auto;}
            p { clear: both; }
            em { font-weight: bold; padding-right: 1em; vertical-align: top; }

        </style>
        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>
        <script type="text/javascript" src="/js/jquery.cookie.js"></script>
        <script type="text/javascript" src="/js/jquery.validate.min.js"></script>
        <script type="text/javascript" src="/js/jquery.jgrowl.js"></script>
        <script type="text/javascript" src="/js/jquery-ui-1.8.13.custom.min.js"></script>	
        <script type="text/javascript" src="/js/jquery.dataTables.min.js"></script>



        <script type="text/javascript" src="/js/admin.nocache.js"></script>
        <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> 

        <script language="javascript">
            function doLogin()
            {
                document.location.href="<%=userService.createLoginURL(request.getRequestURI())%>";
            }       
            
            
        </script>
    </head>
    <body>
        <h1>Memory of a Place - Admin Console</h1>
        <%
        if (userService.isUserLoggedIn()) {
            User user = userService.getCurrentUser();
           long adminType = com.google.memoryofaplace.BLAdmins.getAdminUser(user.getEmail());
        %>
        <p>Hello, <b><%= user.getNickname() %></b>! (You can
            <a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
            <%   if (adminType!=-1) { %>
        <script>
            admUser = "<%= user.getNickname() %>";
            $(document).ready(function() {

            	initDialogs();            	
               	$("#general-tabs").tabs({
                    cookie: {
                        // store cookie for a day, without, it would be a session cookie
                        expires: 1
                    },
                    show: function(event, ui) {loadGeneralTab(ui.index);}
            	});                        	          	            	
            } );
                        

        </script>

        <div id="loadingScreen"></div>

        <div id="general-tabs">
            <ul>
                <li><a href="#tabs-1">Places</a></li>
                <li><a href="#tabs-2">Denounces</a></li>
                <li><a href="#tabs-3">Admin Users</a></li>
            </ul>
            <div id="tabs-1">
                <div id="container_places_list"  class="ex_highlight_row">
                    <table id="places_list" class="display">
                        <thead>
                            <tr> 
                                <th width="5%">CodPlace</th>
                                <th width="20%">Name</th> 
                                <th width="20%">Description</th> 
                                <th width="10%">Type</th> 
                                <th width="15%">Category Type</th>
                                <th width="15%">Created by</th>
                                <th width="15%">Creation</th> 
                            </tr> 
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>		
            </div>
            <div id="tabs-2">
                <p>TAB 2 content</p>
            </div>
            <div id="tabs-3">
                <p>TAB 3 content</p>
            </div>
        </div>
    </div>
    <div id="dialog-form" title="Edit Place Data"
         style="display: none">       
        <form id="placeForm" onsubmit="return false"  class="cmxform">
            <fieldset>
                <div style="float: left; width: 50%; height:auto">
                    <p>
                        <label for="codPlace">codPlace:</label><input type="text"
                                                                      id="codplace" size="5" disabled/>
                    </p>
                    <p>	
                        <label for="name">name:</label>
                        <input type="text" id="name" name="name" class="required" minlength="2"
                               size="40" />
                    </p>
                    <p>
                        <label for="description">description:</label>
                        <textarea id="description" name="description" rows="2" cols="35"></textarea>
                    </p>	
                    <p>
                        <label for="type">type:</label> <select id="type">
                            <option value="1">PLACE_TYPE_1</option>
                            <option value="2">PLACE_TYPE_2</option>
                            <option value="3">PLACE_TYPE_3</option>
                        </select> 
                    </p>
                    <p>
                        <label for="status">status:</label> <select id="status">
                            <option value="0">DRAFT</option>
                            <option value="1">PUBLISHED</option>
                            <option value="-1">DELETED</option>`
                        </select> </p> 
                    <p>
                        <label for="categorytype">categoryType:</label> <select
                            id="categorytype">
                            <option value="1">PLACE_CATEGORY_TYPE_1</option>
                            <option value="2">PLACE_CATEGORY_TYPE_2</option>
                            <option value="3">PLACE_CATEGORY_TYPE_3</option>
                        </select>
                    </p>
                    <p>
                        <label for="creation">creation:</label> <input type="text"
                                                                       id="creation"  size="20" disabled /> <input
                                                                       type="text" id="userCreation" 
                                                                       disabled size="30" /> 
                    </p>
                    <p>
                        <label for="update">update:</label> <input
                            type="text" id="update"  size="20" disabled />
                        <input type="text" id="userUpdate" 
                               disabled size="30" /> 
                    </p>
                    <p>
                        <label for="latitude">latitude
			/ longitude:</label> <input type="text" id="latitude" name="latitude"
                                                    size="8" /> <input type="text" id="longitude" name="longitude" 
                                                    size="8" />
                        <img align="texttop" style="border: 1px solid"
                             src=""
                             width="100" height="100" id="map" />

                    </p>
                    <p>
                        <label for="url" class="url ">url:</label> <input
                            type="text" id="url" name="url"
                            size="55" />
                    </p>
                </div>

                <div style="float: right; width: 50%;">
                    <center>
                        <div id="placeImage" style="width:425px;height:240px;border:1px solid"></div>
                    </center>
                    <p><label for="urlLogo">urlLogo:</label> <input type="text"
                                                                    id="urlLogo" size="55"
                                                                    name="urlLogo" />
                    </p> 
                    <p>
                        <label for="urlStreetView" >urlStreetView:</label> <input
                            type="text" id="urlStreetView" name="urlStreetView" size="55"
                            />
                    </p>
                </div>
                <br/><br/>
                <div style="clear:both;margin-left:50px;margin-right:50px">
                    <br/>
                    <div id="place-tabs">
                        <ul>
                            <li><a href="#tabs-places-1">Photos</a></li>
                            <li><a href="#tabs-places-2">Videos</a></li>
                            <li><a href="#tabs-places-3">Comments</a></li>
                        </ul>
                        <div id="tabs-places-1">
                            <div id="container_place_photos_list"  class="ex_highlight_row">
                                <table id="place_photos_list" class="display">
                                    <thead>
                                        <tr> 
                                            <th width="5%">CodPhoto</th>
                                            <th width="5%">Thumbnail</th> 
                                            <th width="5%">Url</th> 
                                            <th width="20%">Title</th> 
                                            <th width="20%">Description</th> 
                                            <th width="10%">Type</th>
                                            <th width="10%">Taken</th>
                                            <th width="20%">Created by</th>
                                            <th width="10%">Creation</th> 
                                        </tr> 
                                    </thead>
                                    <tr>
                                        <td>25598</td>
                                        <td><img src="http://lh3.ggpht.com/9diZ4kiyA6hQzfG_xoQ0yHr5ene_D4_VmaNAzmbGDXWYoqe0mr5eSpk_YAOYKV0h_P87yJd1NSL5kQINkLGC-vWS8uu1=s40"/></td>
                                        <td>This is my title</td>
                                        <td>This is my little description</td>
                                        <td>BEFORE</td>
                                        <td>16-05-2001</td>
                                        <td>inigo.jimenez</td>
                                        <td>17-05-2011</td>
                                    <tr>    
                                    <tr>
                                        <td>25598</td>
                                        <td><img src="http://lh6.ggpht.com/zsj8O_zBLspuL7mo91CtNFeYVHtwXRoBuMU3FnU9m1gyGZIu243xYYAnNEkAgYDcoKv1PyTsscvTxCxzbjmKWJBIAPQ=s40"/></td>
                                        <td>This is my title</td>
                                        <td>This is my little description</td>
                                        <td>BEFORE</td>
                                        <td>16-05-2001</td>
                                        <td>inigo.jimenez</td>
                                        <td>17-05-2011</td>
                                    <tr>


                                    <tbody>
                                    </tbody>
                                </table>
                            </div>	
                        </div>
                        <div id="tabs-places-2">
                            <div id="container_place_videos_list"  class="ex_highlight_row">
                                <table id="place_videos_list" class="display">
                                    <thead>
                                        <tr> 
                                            <th width="5%">CodVideo</th>
                                            <th width="20%">Name</th> 
                                            <th width="20%">Description</th> 
                                            <th width="10%">Type</th> 
                                            <th width="15%">Category Type</th>
                                            <th width="15%">Created by</th>
                                            <th width="15%">Creation</th> 
                                        </tr> 
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>	
                        </div>
                        <div id="tabs-places-3">
                            <div id="container_place_comments_list"  class="ex_highlight_row">
                                <table id="place_comments_list" class="display">
                                    <thead>
                                        <tr> 
                                            <th width="5%">CodPlace</th>
                                            <th width="20%">Name</th> 
                                            <th width="20%">Description</th> 
                                            <th width="10%">Type</th> 
                                            <th width="15%">Category Type</th>
                                            <th width="15%">Created by</th>
                                            <th width="15%">Creation</th> 
                                        </tr> 
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
</div>

<%} else {%>
Permission Denied. You are not admin. 
<%}%>

<%
} else {
%>
<button name="submit_button" id="submit_button" style="padding:5px;margin-top:20px;" onClick="doLogin()">
    <img src="http://www.google.com/favicon.ico" alt="Sign in with a Google Account" style="margin-bottom:-3px;">&nbsp; Sign in using your Google Account
</button>
</p>
<%
}
%>

</body>
</html>











